/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Application;

import Graph.*;
import Redistribution.Redistribution;
import Parser.*;

import java.util.ArrayList;
import java.util.List;
import java.io.*;
import org.xml.sax.SAXException;

/**
 *
 * @author oliviersputael
 */
public class Main {

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		Graph G1 = new Graph();
		Graph G2 = new Graph();
		List<Variables> varsG1 = new ArrayList<Variables>();
		List<Variables> varsG2 = new ArrayList<Variables>();
		List<Color> colorsG1 = new ArrayList<Color>();
		List<Color> colorsG2 = new ArrayList<Color>();
		
		try {
			System.out.println("Fichier contenant les infos des couleurs : ");
			//colorsG1 = loadColorsFromFile("Datas/Colors/" + in.readLine());
			colorsG1 = loadColorsFromFile("Datas/Colors/Colors-Thesis-Ex-G1.xml");
			G1.addColorListToGraph(colorsG1);
			System.out.println("Fichier contenant les infos des couleurs : ");
			//colorsG2 = loadColorsFromFile("Datas/Colors/" + in.readLine());
			colorsG2 = loadColorsFromFile("Datas/Colors/Colors-Thesis-Ex-G2.xml");
			G2.addColorListToGraph(colorsG2);
			System.out.print("\nFichier contenant les infos des variables : ");
			//varsG1 = loadVarsFromFile("Datas/Variables/" + in.readLine());
			varsG1 = loadVarsFromFile("Datas/Variables/Variables-Thesis-Ex-G1.xml");
			System.out.print("Fichier contenant les infos des variables : ");
			//varsG2 = loadVarsFromFile("Datas/Variables/" + in.readLine());
			varsG2 = loadVarsFromFile("Datas/Variables/Variables-Thesis-Ex-G2.xml");
			
			System.out.print("Fichier contenant les infos des noeuds : ");
			//G1.addNodeListToGraph(loadNodesFromFile("Datas/Nodes/" + in.readLine(), varsG1));
			G1.addNodeListToGraph(loadNodesFromFile("Datas/Nodes/Nodes-Thesis-Ex-G1.xml", varsG1, colorsG1));
			System.out.print("Fichier contenant les infos des noeuds : ");
			//G2.addNodeListToGraph(loadNodesFromFile("Datas/Nodes/" + in.readLine(), varsG2));
			G2.addNodeListToGraph(loadNodesFromFile("Datas/Nodes/Nodes-Thesis-Ex-G2.xml", varsG2, colorsG2));
			
			G1.generateEdges();
			G2.generateEdges();
			
			System.out.println("\nG2 number of nodes: " + G2.getNodes().size());
			
			/*System.out.println("Edges of G1 : ");
			for (int i = 0; i < G1.getNumberOfEdges(); i++) {
				System.out.println("[ " +	G1.getEdgesFromID(i).getNode1().getInstruction().getLabel() + ", " + 
											G1.getEdgesFromID(i).getNode2().getInstruction().getLabel() + " ]");
			}
			
			System.out.println("Edges of G2 : ");
			for (int i = 0; i < G2.getNumberOfEdges(); i++) {
				System.out.println("[ " +	G2.getEdgesFromID(i).getNode1().getInstruction().getLabel() + ", " + 
											G2.getEdgesFromID(i).getNode2().getInstruction().getLabel() + " ]");
			}*/
			
			// comparing graph
			Redistribution redistribution = new Redistribution(G1, G2, colorsG2, 0.5, 1.0, 0.1, 0.5, 10);
			
			/*System.out.println("graphComparison1");
			System.out.println(redistribution.getFirstCompareGraph());
			
			System.out.println("graphComparison2");
			System.out.println(redistribution.getSecondCompareGraph());

			System.out.println("MCS = ");
			System.out.println(redistribution.getMCS());*/
			
			//System.out.println("G2:");
			//System.out.println(redistribution.getNewGraph());
		}
		catch (Exception ex) {
			System.out.println("Error : " + ex.getMessage());
		}
	}
	
	public static List<Variables> loadVarsFromFile (String filename) throws SAXException, FileNotFoundException, IOException  {
		VariablesParser vParser = new VariablesParser();
		
		return vParser.getVariablesFromFile(filename);
	}
	
	public static List<Color> loadColorsFromFile (String filename) throws SAXException, FileNotFoundException, IOException {
		ColorsParser cParser = new ColorsParser();
		
		return cParser.getColorsFromFile(filename);
	}
	
	public static List<Node> loadNodesFromFile (String filemane, List<Variables> vars, List<Color> cols) throws SAXException, FileNotFoundException, IOException  {
		NodesParser nParser = new NodesParser();
		
		return nParser.getNodesFromFile(filemane, vars, cols);
	}
	
	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
}
